#!/usr/bin/env python
#coding: utf-8

import logging
import os
import sys
import datetime

from logging.handlers import RotatingFileHandler

#日志名称以当前日期命名
date = datetime.datetime.now().strftime('%Y%m%d')
logfilename = ("./logs/mm_crawler_%s.log" % date)
#日志写入方式，a为追加，w为覆盖
logfilemode = "w" # 'w' 'a'
#日志保存路径
path = os.getcwd() + "/logs"
if not os.path.exists(path):
    os.mkdir(path)

def setRotatingFile():
    logging.basicConfig(level = logging.DEBUG,
							format = '[%(asctime)s][%(filename)s line:%(lineno)d][pid=%(process)d][thread id=%(thread)d][%(levelname)s] %(message)s',
							datefmt = '',
							filemode = logfilemode
							)
    RtHandler = RotatingFileHandler(logfilename, maxBytes=10*1024*1024, backupCount=30)
    RtHandler.setLevel(logging.DEBUG)
    formatter = logging.Formatter('[%(asctime)s][%(filename)s line:%(lineno)d][pid=%(process)d][thread id=%(thread)d][%(levelname)s] %(message)s')
    RtHandler.setFormatter(formatter)
    logging.getLogger('mm_crawler.log').addHandler(RtHandler)

setRotatingFile()
logger = logging.getLogger('mm_crawler.log')   
   